<?php

class Application_Form_RegisterForm extends Zend_Dojo_Form {

    public function init() {
        $this->setAction('register');
        $this->setMethod('post');
        $this->setAttrib('enctype', 'multipart/form-data');

        $this->setAttrib('class', 'well');

        $username = $this->addElement('text', 'username', array(
            'filters' => array('StringTrim', 'StringToLower'),
            'validators' => array(
                'Alpha',
                array('StringLength', false, array(3, 20)),
            ),
            'required' => true,
            'class' => 'input-small span3',
            'placeholder' => 'Nombre de usuario',
            'label' => 'Nombre de usuario:'
                ));

        $password = $this->addElement('password', 'password', array(
            'filters' => array('StringTrim'),
            'validators' => array(
                'Alnum',
                array('StringLength', false, array(6, 20)),
            ),
            'required' => true,
            'class' => 'input-small span3',
            'placeholder' => 'Password',
            'label' => 'Password:',
            'data-typetoggle' => '#showpassword'
                ));

        $showPassword = $this->addElement('checkbox', 'showpassword', array(
            'required' => false,
            'ignore' => true,
            'label' => 'Mostrar password'
                ));

        $age = $this->addElement('text', 'age', array(
            'filters' => array('StringTrim'),
            'validators' => array(
                'int',
                array('StringLength', false, array(1, 3)),
            ),
            'required' => true,
            'class' => 'input-small span3',
            'placeholder' => 'Edad',
            'label' => 'Edad:'
                ));

        $latitude = $this->addElement('text', 'latitude', array(
            'filters' => array('StringTrim'),
            'readonly' => 'readonly',
            'required' => true,
            'class' => 'input-small span3',
            'placeholder' => '',
            'label' => 'Latitude:'
                ));

        $longitude = $this->addElement('text', 'longitude', array(
            'filters' => array('StringTrim'),
            'readonly' => 'readonly',
            'required' => true,
            'class' => 'input-small span3',
            'placeholder' => '',
            'label' => 'Longitude:'
                ));

        $this->addElement('file', 'userPhoto', array(
            'label' => 'Seleccione una Foto',
            'required' => true
        ));
        $this->userPhoto->addValidator('Extension', false, 'jpg,png,gif,jpeg');
        $this->userPhoto->addValidator('Size', false, '102400000'); //100mb
        $this->userPhoto->setDestination(APPLICATION_PATH . "/../public/uploads/");
        $this->userPhoto->setValueDisabled(true);

        $register = $this->addElement('submit', 'register', array(
            'required' => false,
            'ignore' => true,
            'label' => 'Guardar',
            'class' => 'btn'
                ));

        $this->addElement(
                'hidden', 'dummy', array(
                    'required' => false,
                    'ignore' => true,
                    'autoInsertNotEmptyValidator' => false,
                    'decorators' => array(
                        array(
                            'HtmlTag', array(
                                'tag' => 'div',
                                'id' => 'map'
                            )
                        )
                    )
                )
        );
        $this->dummy->clearValidators();

        // We want to display a 'failed authentication' message if necessary;
        // we'll do that with the form 'description', so we need to add that
        // decorator.
        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form')),
            array('Description', array('placement' => 'prepend')),
            'Form'
        ));

        // And finally add some CSRF protection
        $this->addElement('hash', 'csrf', array(
            'ignore' => true,
        ));
        
    }

}